package com.mz.ozy.mvp.presenter;

import android.content.Context;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.constants.Constants;
import com.mz.ozy.mvp.model.CodeModel;
import com.mz.ozy.mvp.view.CodeContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import io.reactivex.disposables.Disposable;
import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class CodePresenter extends BasePresenterImpl<CodeContract.View> implements CodeContract.Presenter {

    public static final String MSG_TYPE_REG = "R";    //注册
    public static final String MSG_TYPE_LOGIN = "R";  //登录
    public static final String MSG_TYPE_PASS = "U";   //修改密码
    public static final String MSG_TYPE_FIND = "P";   //修改密码
    public static final String MSG_TYPE_BIND = "R";   //绑定

    private CodeModel mCodeModel;

    public CodePresenter(CodeContract.View view) {
        attachView(view);
        mCodeModel = new CodeModel();
    }


    @Override
    public void onGetCode(Context context, String mobilePhone, String type) {
        mCodeModel.onGetCode(context, mobilePhone, type)
                .compose(RxUtil.rxSchedulerHelper(mView.bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.onGetCodeSuccess(jsonObject);
                    }

                    @Override
                    public MyObserver setTransCode(String transCode) {
                        return super.setTransCode(transCode);
                    }

                    @Override
                    public void onSubscribe(Disposable d) {
                        super.onSubscribe(d);
                    }

                    @Override
                    public void onNext(ResponseBody responseBody) {
                        super.onNext(responseBody);
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }

                    @Override
                    public void onComplete() {
                        super.onComplete();
                    }
                }.setTransCode(Constants.TransCode.TransCode10001));
    }
}
